var cm=multiCheckModel_create();
//gridColumns.unshift(cm);
//供应商订单明细
var gridColumns_sm=NumberColumn_create()
var gridColumns=[gridColumns_sm,cm,{
	hidden: true,
    resizable: false,
	dataIndex: "inlayDiamondId"
}, {
	hidden: true,
    resizable: false,
	dataIndex: "inlayLevel"
}, {
    header: "钻托名称",
    align : 'center',
    width : 80,
    sortable: true,
    resizable: true,
    dataIndex: "inlayName"
}, {
    header: "钻托编号",
    align : 'center',
    width : 80,
    sortable: true,
    resizable: true,
    dataIndex: "inlayNumber"
}, {
    header: "钻托类型",
    align : 'center',
    width : 70,
    sortable: true,
    resizable: true,
    dataIndex: "inlayType"
},  {
    header: "18K重量",
    align : 'center',
    width : 70,
    sortable: true,
    resizable: true,
    dataIndex: "k18Weight"
}, {
    header: "18K价格",
    align : 'center',
    width : 70,
    sortable: true,
    resizable: true,
    dataIndex: "k18Price"
},  {
    header: "PT900重量",
    align : 'center',
    width : 70,
    sortable: true,
    resizable: true,
    dataIndex: "pt900Weight"
}, {
    header: "PT900价格",
    align : 'center',
    width : 70,
    sortable: true,
    resizable: true,
    dataIndex: "pt900Price"
},  {
    header: "PT950重量",
    align : 'center',
    width : 70,
    sortable: true,
    resizable: true,
    dataIndex: "pt950Weight"
}, {
    header: "PT950价格",
    align : 'center',
    width : 70,
    sortable: true,
    resizable: true,
    dataIndex: "pt950Price"
},  {
    header: "工厂编号",
    align : 'center',
    width : 80,
    sortable: true,
    resizable: true,
    dataIndex: "factoryNumber"
},  {
    header: "钻托所属",
    align : 'center',
    width : 100,
    sortable: true,
    resizable: true,
    dataIndex: "cmpName",
    renderer:function(value, metaData, record, rowIndex, colIndex, store){
		if (record.get('inlayLevel') == 'A') {
			return '<span style="cursor:pointer;color:blue;">管理员</span>';
		} else {
			return '<span style="cursor:pointer;color:red;">'+value+'</span>';
		}
	}
}, {
    header: "操作",
    align : 'center',
    width : 60,
    resizable: true,
	hideable :false,
	renderer:function(value, metaData, record, rowIndex, colIndex, store){
		if (record.get('inlayLevel') == 'A') {
			return '<span style="cursor:pointer;color:blue;">修改</span>';
		} else {
			return '修改';
		}
	}
}]

var gridModel=new Ext.grid.ColumnModel({
  defaultSortable: true,
  defaultWidth: 85,
  columns:gridColumns
})

var gridStore=new Ext.data.JsonStore({
	url:'queryInlayDiamondList.action',
	totalProperty: 'obj.totalSize', 
	successProperty :'success',
	root:'obj.returnBolist',
	messageProperty:'msg',
	fields:getFieldsFromColumns(gridColumns),
	listeners:{
		load:function(store){
			store.each(function(rd){
				rd.data.type=store.reader.jsonData.obj.type;
			})
		}
	}
});

var orderGrid = new Ext.grid.GridPanel({
	store: gridStore,
	cm: gridModel,
	sm:cm,
	listeners:{
		cellclick:function(grid, row,column){
			var cm = grid.getColumnModel();
			var header = cm.getColumnHeader(column);
			if (header == '操作') {
				var rd=grid.getStore().getAt(row);
				if (rd.get('inlayLevel') == 'A') {
					addProxy(rd.get('inlayDiamondId'));
				} else {
					Ext.Msg.alert('提示','该钻托不属于管理员钻托，不能进行修改操作!')
				}
			}
		}
	},
	bbar : new Ext.PagingToolbar({
		pageSize : 100,
		store : gridStore,
		displayInfo:true,
		displyMsg : '显示第{0}条到第{1}条记录，一共{2}条',
		emptyMsg : "没有记录",
		items:[{
			text:'删除',
			handler:function(bt,e){
				var grid = bt.ownerCt.ownerCt;
				var cm = grid.getSelectionModel();
				var rds=cm.getSelections();
						
				var userStr=null;
				Ext.each(rds,function(rd){
					userStr=(userStr!=null)?(userStr+";"+rd.get('inlayDiamondId')):rd.get('inlayDiamondId');
				});
				if(Ext.isEmpty(userStr)){
					Ext.Msg.alert('提示','没有要删除的数据!')
					return;
				}
		            	Ext.Msg.confirm("提示",'你确信要执行删除操作？' ,function(at,mg){
		            		if(at=='yes'){
		            			
								var con = new connection({
		        					url: 'delInlayDiamond.action',
		        					params: {
		            					inlayDiaIds: userStr
		        					},
		        					success: function(result, response){
		            					var alt=result.success?'成功':'失败';
										Ext.Msg.alert(alt, result.msg);
										gridStore.load({});
		        					},
		        					failure : function(result, response) {
					        			Ext.Msg.alert('异常','系统异常,请联系管理员');
									}
		    					});
		    					con.submit();
		            		}
		            	});
		            }
		}]
	})
});

var queryOrderPanel=new Ext.FormPanel({
	layout:'column',
	id : 'queryOrderPanel',
	frame:true,
	regetion:'north',
	defaults:{
		columnWidth:0.17,
		layout:'form',
		labelWidth:55,
		defaults:{
			anchor: '90%'
			}
	},
	items:[{
		items:[{
			xtype:'textfield',
			anchor:'85%',
			fieldLabel:'钻托名称', 
			name : 'name',
			id : 'name_fl'
		}]
	},{
		items:[{
			xtype:'textfield',
			anchor:'85%',
			fieldLabel:'钻托编号', 
			name : 'no',
			id : 'no_fl'
		}]
	},{
		items:[{
			xtype: 'combo',
			anchor:'85%',
			store:inlayType_Store,
			triggerAction: 'all',
			valueField:'value',
			displayField:'name',
			mode: 'local',
			fieldLabel:'钻托类型', 
			name : 'type',
			id : 'type_fl'
		}]
	},{
		columnWidth:0.25,
			xtype:'panel',
			layout:'column',
			defaults:{
				anchor: '85%',
				xtype:'panel',
				layout:'form',
				defaults:{
					xtype:'textfield',
					anchor: '95%'
				}
			},
			items:[{
				columnWidth:0.58,
				items:[{
					xtype:'numberfield',
					fieldLabel:'18K价格',
					name : 'priceFr',
					id : 'priceFr_fl'
				}]
			},{
				columnWidth:0.42,
				labelWidth:10,
				items:[{
					labelSeparator:'-',
					fieldLabel:'-',
					xtype:'numberfield',
					name : 'priceTo',
					id : 'priceTo_fl'
				}]
			}]
	},{
		columnWidth:0.1,
		items:[{
			xtype:'button',
			text:'查询',
			id:'searchBt',
			anchor: '40%',
			handler:function(bt, e){
				var params=panel_gatherData('queryOrderPanel');
//				queryManager(data);
				Ext.apply(gridStore.baseParams, {
					inlayDiaPriFr:params.priceFr,
					inlayDiaPriTo: params.priceTo,
					inlayDiaName:params.name,
					inlayDiaType:params.type,
					inlayDiaCode:params.no
				})
				gridStore.load({});
				orderGrid.getView().refresh();
			}
		}]
	}]
});


function queryManager(data){
	
}

Ext.onReady(function() {
	new Ext.Viewport({
		layout: 'fit',
		items: [{
				xtype: 'panel',
				layout : 'border',
				tbar:[{
					icon: 'back/extJs/images/image_add.png',
					text:'上传钻托',
					handler:function(){
						addProxy();
					}
				}],
				items : [{
					region : 'north',
					split : true,
					border : false,
					height : 40,
					collapseMode : 'mini',
					layout : 'fit',
					items : [queryOrderPanel]
				}, {
					region : 'center',
					split : true,
					border : false,
					layout : 'fit',
					items : [orderGrid]
				}]
//				listeners:{
//					render:function(){addProxy(function(){})}
//				}
		}]
	});
});
	
  